﻿using System.Collections.ObjectModel;
using Caliburn;
using Caliburn.Events.Brokering;
using Caliburn.Services;
using NServiceBus.Management.Shell.Application;

namespace NServiceBus.Management.Shell.Presenters
{
    public class ShellPresenter
    {
        private ObservableCollection<object> _presenters = new ObservableCollection<object>();
        public ObservableCollection<object> Presenters
        {
            get { return _presenters; }
        }

        [Subscribe("event://Shell/Presenter/AddRequested")]
        public void AddPresenterRequested(object presenter)
        {
            if (_presenters.Contains(presenter))
                _presenters.Remove(presenter);

            _presenters.Insert(0, presenter);
        }

        [Subscribe("event://Shell/Presenter/RemoveRequested")]
        public void RemovePresenterRequested(object presenter)
        {
            _presenters.Remove(presenter);
        }

        public void About()
        {
            DI.Resolve<IPlatformCapabilities>()
                .MessageBox.Show("Simple Todo list demo.", "Caliburn Demo");
        }

        public void Exit()
        {
            App.Current.Shutdown();
            //Application.Current.Shutdown();
        }
    }
}
